package net.towee.client.com.app.view;

import net.towee.client.com.app.AppController.Display;
import net.towee.client.i18n.ToweeConstants;
import net.towee.client.resources.ClientResource;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.inject.Inject;

public class AppView extends FlowPanel implements Display {
	private final Label feedbackButton = new Label();
	private final Label exitButton = new Label();
	private final FlowPanel topPanel;
	private final FlowPanel body;
	private final FlowPanel connection;
	
	@Inject
	public AppView(ClientResource resource, ToweeConstants constants){
		// Inject css to DOM
		resource.css().ensureInjected();
		
		// Create panels
		this.topPanel = new FlowPanel();
		this.topPanel.setStyleName( resource.css().topPanel() );
		add(this.topPanel);
		
		// Create body
		this.body = new FlowPanel();
		this.body.setStyleName( resource.css().bodyPanel() );
		add(this.body);
		
		// Add Logo
		Image logo = new Image(resource.logo());
		logo.setStyleName(resource.css().logo());
		add(logo);
		
		// Create connection
		connection = new FlowPanel();
		connection.setStyleName( resource.css().connectionController() );
		add(connection);
		
		// Create feedback button
		feedbackButton.setText( constants.leaveFeedback() );
		feedbackButton.setStyleName( resource.css().feedBackButton() );
		add(feedbackButton);
		
		// Create exit button
		exitButton.setText( constants.exit() );
		exitButton.setStyleName( resource.css().exitButton() );
		add(exitButton);
		
		exitButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				Window.Location.replace(GWT.getHostPageBaseURL()+"logout");
			}
		});
	}
	
	@Override
	public HasWidgets getTopContainer() {
		return topPanel;
	}

	@Override
	public HasWidgets getBodyContainer() {
		return body;
	}

	@Override
	public HasWidgets getBottomContainer() {
		return null;
	}

	@Override
	public HasWidgets getConnectionStataContainer() {
		return connection;
	}

	@Override
	public HasClickHandlers getFeedbackButton() {
		return feedbackButton;
	}

}
